{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## KFServing Model Explainability\n",
    "\n",
    "Install the necessary libraries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n",
      "/usr/local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint8 = np.dtype([(\"qint8\", np.int8, 1)])\n",
      "/usr/local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint8 = np.dtype([(\"quint8\", np.uint8, 1)])\n",
      "/usr/local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint16 = np.dtype([(\"qint16\", np.int16, 1)])\n",
      "/usr/local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint16 = np.dtype([(\"quint16\", np.uint16, 1)])\n",
      "/usr/local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint32 = np.dtype([(\"qint32\", np.int32, 1)])\n",
      "/usr/local/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  np_resource = np.dtype([(\"resource\", np.ubyte, 1)])\n",
      "/usr/local/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:541: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint8 = np.dtype([(\"qint8\", np.int8, 1)])\n",
      "/usr/local/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:542: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint8 = np.dtype([(\"quint8\", np.uint8, 1)])\n",
      "/usr/local/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:543: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint16 = np.dtype([(\"qint16\", np.int16, 1)])\n",
      "/usr/local/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:544: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint16 = np.dtype([(\"quint16\", np.uint16, 1)])\n",
      "/usr/local/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:545: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint32 = np.dtype([(\"qint32\", np.int32, 1)])\n",
      "/usr/local/lib/python3.7/site-packages/tensorboard/compat/tensorflow_stub/dtypes.py:550: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  np_resource = np.dtype([(\"resource\", np.ubyte, 1)])\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import sys\n",
    "import requests\n",
    "import json\n",
    "from matplotlib import pyplot as plt\n",
    "import numpy as np\n",
    "from aix360.datasets import MNISTDataset\n",
    "from keras.applications import inception_v3 as inc_net\n",
    "from keras.preprocessing import image\n",
    "from keras.applications.imagenet_utils import decode_predictions\n",
    "import time\n",
    "from skimage.color import (\n",
    "    gray2rgb,\n",
    "    rgb2gray,\n",
    "    label2rgb,\n",
    ")  # since the code wants color images"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Get endpoint, host headers, and load the image from a file or from the MNIST dataset."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "************************************************************\n",
      "************************************************************\n",
      "************************************************************\n",
      "starting query\n"
     ]
    }
   ],
   "source": [
    "print(\"************************************************************\")\n",
    "print(\"************************************************************\")\n",
    "print(\"************************************************************\")\n",
    "print(\"starting query\")\n",
    "\n",
    "if len(sys.argv) < 3:\n",
    "    raise Exception(\"No endpoint specified. \")\n",
    "\n",
    "endpoint = sys.argv[1]\n",
    "headers = {\"Host\": sys.argv[2]}\n",
    "test_num = 1002\n",
    "is_file = False\n",
    "if len(sys.argv) > 3:\n",
    "    try:\n",
    "        test_num = int(sys.argv[2])\n",
    "    except:\n",
    "        is_file = True\n",
    "\n",
    "if is_file:\n",
    "    inputs = open(sys.argv[2])\n",
    "    inputs = json.load(inputs)\n",
    "    actual = \"unk\"\n",
    "else:\n",
    "    data = MNISTDataset()\n",
    "    inputs = data.test_data[test_num]\n",
    "    labels = data.test_labels[test_num]\n",
    "    actual = 0\n",
    "    for x in range(1, len(labels)):\n",
    "        if labels[x] != 0:\n",
    "            actual = x\n",
    "    inputs = gray2rgb(inputs.reshape((-1, 28, 28)))\n",
    "    inputs = np.reshape(inputs, (28, 28, 3))\n",
    "input_image = {\"instances\": [inputs.tolist()]}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Display the input image to be used."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAkEAAAJOCAYAAACwUtN4AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAa4ElEQVR4nO3df7DldX3f8ddb1x+pu4koiIj4o9ampdag3XHyQ8pWojUOuP6KSNOIJszaFjNYaavSSWKmJrWipNFWWyiMtOCvUYy0aIyjW0ymxJFljIIEtYoVXGHQEpHsiHA//eMempudXXbZ+73n3L3vx2NmZ8/9nnPf38/l68En3+8559YYIwAA3Txo0QsAAFgEEQQAtCSCAICWRBAA0JIIAgBaEkEAQEsiCHhAqurcqvovUz/2IGaNqvobU8wCSJLyOUHQV1W9Ksk5SZ6S5PtJPprkTWOMOxa5rn2pqpHkqWOMr+3jvv+Z5NIxxiTBBfTgTBA0VVXnJPl3Sf5lkp9I8tNJnpjkU1X10P18z6b5rRBgbYkgaKiqfjzJbyX5tTHGH4wxfjTGuCnJy5M8Kck/nj3uzVX14aq6tKq+n+RVs22Xrpj1yqr6ZlV9t6p+vapuqqqfX/H9l85uP2l2SeuMqvo/VXV7Vf3rFXOeVVVXV9UdVbW7qv7D/mLsAD/btqq6uar+VVXdNpv1oqp6QVV9paq+V1XnHux+q+p5VXVjVf15Vb27qq6qqjNX3P8rVXVDVf3fqvpkVT3xga4ZWAwRBD39bJKHJ7l85cYxxg+SfDzJc1ds3p7kw0kemeSylY+vquOTvDvJLyU5JstnlI49wL6fneQnk5yc5Deq6m/Ptt+b5J8nOTLJz8zu/2cP8Oe6z2Oz/PMdm+Q3klyY5bD7e0lOTPLrVfXkA+23qo7M8s/+piSPTnJjlv/ZZXb/9iTnJnlJkqOS/FGS9x/imoE5E0HQ05FJbh9j3LOP+3bP7r/P1WOM3x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AaOmAL4wG1rdTTjllslkXX3zxZLPWs6l/zte//vWTzdqzZ89ks4D750wQANCSCAIAWhJBAEBLIggAaEkEAQAtiSAAoCURBAC0JIIAgJZEEADQkggCAFoSQQBASyIIAGhJBAEALYkgAKAlEQQAtCSCAICWRBAA0JIIAgBaqjHG/HZWNb+dwYS2bNky2axHPvKRk81Kkssvv3yyWc94xjMmmzW1j3/845PNOu200yablSR79uyZdB4wuV1jjK17b3QmCABoSQQBAC2JIACgJREEALQkggCAlkQQANCSCAIAWhJBAEBLIggAaEkEAQAtiSAAoCURBAC0JIIAgJZEEADQkggCAFoSQQBASyIIAGhJBAEALYkgAKClTYteABwOzjzzzMlmnXfeeZPN6uQd73jHZLP27Nkz2Szg8OVMEADQkggCAFoSQQBASyIIAGhJBAEALYkgAKAlEQQAtCSCAICWRBAA0JIIAgBaEkEAQEsiCABoSQQBAC2JIACgJREEALQkggCAlkQQANCSCAIAWtq06AXAfbZs2TLZrDPPPHOyWUly/vnnTzZraWlpsllTu/POOyedt3379slmXXXVVZPNmtrpp58+2azHPvaxk82a2uMf//hJ551zzjmTzoMHypkgAKAlEQQAtCSCAICWRBAA0JIIAgBaEkEAQEsiCABoSQQBAC2JIACgJREEALQkggCAlkQQANCSCAIAWhJBAEBLIggAaEkEAQAtiSAAoCURBAC0JIIAgJY2LXoBcJ+TTjppslnnnXfeZLOSZGlpabJZY4zJZk3thz/84aTzHvOYx0w2613vetdks174whdONitJjjrqqMlm3XPPPZPNSpIrr7xyslmf+MQnJpsF64EzQQBASyIIAGhJBAEALYkgAKAlEQQAtHTACKqq46pqZ1V9uaqur6qzZ9sfVVWfqqqvzv4+Yu2XCwAwjYM5E3RPknPGGMcn+ekkZ1XV8UnemOTTY4ynJvn07GsAgMPCASNojLF7jHHt7PadSW5IcmyS7UkumT3skiQvWqtFAgBM7QF9WGJVPSnJM5J8LsnRY4zds7u+k+To/XzPjiQ7Dn2JAADTO+gXRlfV5iQfSfK6Mcb3V943lj8Cd58fgzvGuG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RdCxSb614uubs8H/4a9TI8kfVtWuqtqx6MU0d/QYY/fs9neSHL3IxTT22qr64uxymUsxc1BVT0ryjCSfi+fBQux1DJIN+jxYTxHE+vDsMcYzk/xCkrNmlwhYsLF83Xp9XLvu5T1JnpLkhCS7k7xjscvZ+Kpqc5KPJHndGOP7K+/zPJiPfRyDDfs8WE8RdEuS41Z8/fjZNuZojHHL7O/bknw0y5cpWYxbZ9fo77tWf9uC19POGOPWMca9Y4ylJBfG82FNVdVDsvx/vpeNMS6fbfY8mKN9HYON/DxYTxH0+SRPraonV9VDk7wiyRULXlMrVfWI2YvhUlWPSPK8JNfd/3exhq5Icsbs9hlJPrbAtbR03//5zrw4ng9rpqoqyUVJbhhjnL/iLs+DOdnfMdjIz4N18+6wJJm97e7fJ3lwkovHGL+94CW1UlV/Pctnf5JkU5L3OQbzUVXvT7ItyZFJbk3ym0l+P8mHkjwhyTeTvHyM4YW7a2Q/x2Bbli8BjCQ3JXnNitenMKGqenaSP0rypSRLs83nZvk1KZ4Hc3A/x+D0bNDnwbqKIACAeVlPl8MAAOZGBAEALYkgAKAlEQQAtCSCAICWRBAA0JIIAgBa+n+QdF2/32mhGwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 720x720 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig0 = (inputs[:, :, 0] + 0.5) * 255\n",
    "f, axarr = plt.subplots(1, 1, figsize=(10, 10))\n",
    "axarr.set_title(\"Original Image\")\n",
    "axarr.imshow(fig0, cmap=\"gray\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Send the image to the inferenceservice."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Sending Explain Query\n",
      "TIME TAKEN:  1.2478861808776855\n"
     ]
    }
   ],
   "source": [
    "print(\"Sending Explain Query\")\n",
    "\n",
    "x = time.time()\n",
    "\n",
    "res = requests.post(endpoint, json=input_image, headers=headers)\n",
    "\n",
    "print(\"TIME TAKEN: \", time.time() - x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Unwrap the response from the inferenceservice and display the explanations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/usr/local/lib/python3.7/site-packages/skimage/color/colorlabel.py:111: UserWarning: Negative intensities in `image` are not supported\n",
      "  bg_color, image_alpha)\n",
      "Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
      "Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
      "Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
      "Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
      "Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
      "Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
      "Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
      "Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
      "Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n",
      "Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<Response [200]>\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAqwAAAFSCAYAAAA3so3EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAg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bFeumZiK5CTxhhTRiMrjTGm1PtokpNPkRNJXIcVAAAAXYyCFQAAAFmjYAUAAEDWenINKxpjvRmqYr0ZqmBMQVWMKaiCNawAAADoWhSsAAAAyBoFKwAAALJGwQoAAICsUbACAAAgaxSsAAAAyBoFKwAAALJGwQoAAICsUbACAAAgaxSsAAAAyBoFKwAAALJGwQoAAICsUbACAAAgaxSsAAAAyBoFKwAAALJGwQoAAICsOSI63QcAAABgTMywAgAAIGsUrAAAAMgaBSsAAACyRsEKAACArFGwAgAAIGsUrAAAAMja/wNwawq8zlLRqgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 864x432 with 10 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "print(res)\n",
    "if not res.ok:\n",
    "    res.raise_for_status()\n",
    "res_json = res.json()\n",
    "temp = np.array(res_json[\"explanations\"][\"temp\"])\n",
    "masks = np.array(res_json[\"explanations\"][\"masks\"])\n",
    "top_labels = np.array(res_json[\"explanations\"][\"top_labels\"])\n",
    "\n",
    "fig, m_axs = plt.subplots(2, 5, figsize=(12, 6))\n",
    "for i, c_ax in enumerate(m_axs.flatten()):\n",
    "    mask = masks[i]\n",
    "    c_ax.imshow(label2rgb(mask, temp, bg_label=0), interpolation=\"nearest\")\n",
    "    c_ax.set_title(\"Positive for {}\\nActual {}\".format(top_labels[i], actual))\n",
    "    c_ax.axis(\"off\")\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.7.4 64-bit",
   "language": "python",
   "name": "python37464biteac3a92cf4cf48d3b00e9c4589083555"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
